//
//  SDRegisterViewController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDRegisterViewController.h"
#import "UIView+SDExtension.h"

#define padding 20
@interface SDRegisterViewController ()

//手机号码
@property (nonatomic, strong) UITextField *phoneNumTF;
//验证码
@property (nonatomic, strong) UITextField *verfiTF;
//按钮
@property (nonatomic, strong) UIButton *verfiBtn;
//选择按钮
@property (nonatomic, strong) UIButton *boxButton;
//同意协议字符串
@property (nonatomic, strong) UILabel *agreeLb;
//同意协议按钮
@property (nonatomic, strong) UIButton *agreeBtn;
//注册按钮
@property (nonatomic, strong) UIButton *registerBtn;


@end

@implementation SDRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupLayout];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.view endEditing:YES];
}

- (void)setupLayout{
    [self.phoneNumTF mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom).mas_offset(3 * padding);
        make.leading.mas_equalTo(padding);
        make.trailing.mas_equalTo(-padding);
        make.height.mas_equalTo(30);
        
    }];
    [self.verfiTF mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneNumTF.mas_bottom).mas_equalTo(2 * padding);
        make.leading.mas_equalTo(padding);

        make.width.mas_equalTo(self.phoneNumTF.mas_width).multipliedBy(0.6);
        make.height.mas_equalTo(30);
        
    }];
    [self.verfiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.verfiTF.mas_centerY);
        make.leading.mas_equalTo(self.verfiTF.mas_trailing).mas_offset(1.5*padding);
        make.trailing.mas_offset(-padding);
        make.height.mas_equalTo(30);
        
    }];
    [self.agreeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.verfiTF.mas_bottom).mas_offset(2*padding);
        make.leading.mas_equalTo(self.boxButton.mas_trailing).mas_equalTo(padding);
        
    }];
    [self.boxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(3*padding);
        make.centerY.mas_equalTo(self.agreeLb.mas_centerY);

    }];
    [self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.agreeLb.mas_centerY);
        make.leading.mas_equalTo(self.agreeLb.mas_trailing).mas_equalTo(0.5 * padding);
        make.height.mas_equalTo(1);
    }];
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.agreeBtn.mas_bottom).offset(padding);
        make.leading.mas_equalTo(padding);
        make.trailing.mas_equalTo(-padding);
        make.height.mas_equalTo(1.5*padding);
    }];
}

#pragma mark
#pragma mark - 获取验证码方法
- (void)verfiClickButton:(UIButton *)sender{
    
}
#pragma mark
#pragma mark - 同意协议选择按钮
- (void)boxClickButton:(UIButton *)sender{
    sender.selected = !sender.isSelected;
}
#pragma mark
#pragma mark - 阅读用户协议按钮
- (void)agreeClickButton:(UIButton *)sender{
    
}
#pragma mark
#pragma mark - 注册按钮
- (void)registerClickButton:(UIButton *)sender{
    
}

#pragma mark
#pragma mark - lazy 懒加载
- (UITextField *)phoneNumTF{
    if (_phoneNumTF == nil) {
        _phoneNumTF = [[UITextField alloc] init];
        _phoneNumTF.placeholder = @"请输入你的手机号";
        _phoneNumTF.borderStyle = UITextBorderStyleRoundedRect;
        _phoneNumTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.view addSubview:_phoneNumTF];
    }
    return _phoneNumTF;
}
- (UITextField *)verfiTF{
    if (_verfiTF == nil) {
        _verfiTF = [[UITextField alloc] init];
        _verfiTF.placeholder = @"请输入验证码";
        _verfiTF.borderStyle = UITextBorderStyleRoundedRect;
        _verfiTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.view addSubview:_verfiTF];
    }
    return _verfiTF;
}
- (UIButton *)verfiBtn{
    if (_verfiBtn == nil) {
        _verfiBtn = [[UIButton alloc] init];
        [_verfiBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        [_verfiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _verfiBtn.layer.cornerRadius = 5;
        _verfiBtn.layer.masksToBounds = YES;
        _verfiBtn.backgroundColor = [UIColor lightGrayColor];
        [_verfiBtn addTarget:self action:@selector(verfiClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_verfiBtn];

    }
    return _verfiBtn;
}
- (UIButton *)boxButton{
    if (_boxButton == nil) {
        _boxButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_boxButton setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        [_boxButton setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
        
        [_boxButton addTarget:self action:@selector(boxClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_boxButton];
    }
    return _boxButton;
}

- (UILabel *)agreeLb{
    if (_agreeLb == nil) {
        _agreeLb = [[UILabel alloc] init];
        _agreeLb.font = FONT(12);
        _agreeLb.text = @"本人同意并阅读";
        [self.view addSubview:_agreeLb];
    }
    return _agreeLb;
}

- (UIButton *)agreeBtn{
    if (_agreeBtn == nil) {
        _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_agreeBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_agreeBtn setTitle:@"用户协议" forState:UIControlStateNormal];
        [_agreeBtn addTarget:self action:@selector(agreeClickButton:) forControlEvents:UIControlEventTouchUpInside];
        _agreeBtn.titleLabel.font = FONT(12);
        
        [self.view addSubview:_agreeBtn];
    }
    return _agreeBtn;
}
- (UIButton *)registerBtn{
    if (_registerBtn == nil) {
        
        _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _registerBtn.backgroundColor = kThemeColor;
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        _registerBtn.titleLabel.font = FONT(15);
        
        [_registerBtn addTarget:self action:@selector(registerClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_registerBtn];
    }
    return _registerBtn;
}

@end
